from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-12-31 14:02:22.370149
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 31, Dec, 2022
Time: 14:02:27
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.3357
Nobs: 887.000 HQIC: -51.6358
Log likelihood: 11745.5 FPE: 3.12028e-23
AIC: -51.8215 Det(Omega_mle): 2.82081e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296785 0.049304 6.019 0.000
L1.Burgenland 0.105828 0.033852 3.126 0.002
L1.Kärnten -0.106321 0.018176 -5.849 0.000
L1.Niederösterreich 0.213547 0.070986 3.008 0.003
L1.Oberösterreich 0.081408 0.067114 1.213 0.225
L1.Salzburg 0.250304 0.035951 6.962 0.000
L1.Steiermark 0.029630 0.047188 0.628 0.530
L1.Tirol 0.126585 0.038365 3.299 0.001
L1.Vorarlberg -0.060117 0.032973 -1.823 0.068
L1.Wien 0.066513 0.059884 1.111 0.267
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.062304 0.101173 0.616 0.538
L1.Burgenland -0.009250 0.069464 -0.133 0.894
L1.Kärnten 0.049296 0.037298 1.322 0.186
L1.Niederösterreich -0.170918 0.145665 -1.173 0.241
L1.Oberösterreich 0.360443 0.137719 2.617 0.009
L1.Salzburg 0.285813 0.073772 3.874 0.000
L1.Steiermark 0.107792 0.096830 1.113 0.266
L1.Tirol 0.319343 0.078727 4.056 0.000
L1.Vorarlberg 0.025360 0.067661 0.375 0.708
L1.Wien -0.024344 0.122883 -0.198 0.843
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.201052 0.025631 7.844 0.000
L1.Burgenland 0.090481 0.017598 5.142 0.000
L1.Kärnten -0.008751 0.009449 -0.926 0.354
L1.Niederösterreich 0.267493 0.036902 7.249 0.000
L1.Oberösterreich 0.110065 0.034889 3.155 0.002
L1.Salzburg 0.053503 0.018689 2.863 0.004
L1.Steiermark 0.015369 0.024531 0.627 0.531
L1.Tirol 0.101616 0.019944 5.095 0.000
L1.Vorarlberg 0.057354 0.017141 3.346 0.001
L1.Wien 0.112782 0.031131 3.623 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.104887 0.026276 3.992 0.000
L1.Burgenland 0.048252 0.018041 2.675 0.007
L1.Kärnten -0.016303 0.009687 -1.683 0.092
L1.Niederösterreich 0.197915 0.037831 5.232 0.000
L1.Oberösterreich 0.275912 0.035767 7.714 0.000
L1.Salzburg 0.117773 0.019159 6.147 0.000
L1.Steiermark 0.100514 0.025148 3.997 0.000
L1.Tirol 0.125127 0.020446 6.120 0.000
L1.Vorarlberg 0.070552 0.017572 4.015 0.000
L1.Wien -0.025501 0.031914 -0.799 0.424
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.132425 0.047344 2.797 0.005
L1.Burgenland -0.053568 0.032506 -1.648 0.099
L1.Kärnten -0.036202 0.017453 -2.074 0.038
L1.Niederösterreich 0.166612 0.068164 2.444 0.015
L1.Oberösterreich 0.130616 0.064446 2.027 0.043
L1.Salzburg 0.290375 0.034522 8.411 0.000
L1.Steiermark 0.033727 0.045312 0.744 0.457
L1.Tirol 0.159845 0.036840 4.339 0.000
L1.Vorarlberg 0.109423 0.031662 3.456 0.001
L1.Wien 0.068262 0.057503 1.187 0.235
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064019 0.037602 1.703 0.089
L1.Burgenland 0.038480 0.025817 1.490 0.136
L1.Kärnten 0.050162 0.013862 3.619 0.000
L1.Niederösterreich 0.226169 0.054138 4.178 0.000
L1.Oberösterreich 0.265807 0.051185 5.193 0.000
L1.Salzburg 0.060785 0.027418 2.217 0.027
L1.Steiermark -0.006995 0.035988 -0.194 0.846
L1.Tirol 0.157168 0.029260 5.372 0.000
L1.Vorarlberg 0.068711 0.025147 2.732 0.006
L1.Wien 0.076409 0.045671 1.673 0.094
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188376 0.045186 4.169 0.000
L1.Burgenland 0.017651 0.031024 0.569 0.569
L1.Kärnten -0.058648 0.016658 -3.521 0.000
L1.Niederösterreich -0.096113 0.065056 -1.477 0.140
L1.Oberösterreich 0.176984 0.061508 2.877 0.004
L1.Salzburg 0.061357 0.032948 1.862 0.063
L1.Steiermark 0.226233 0.043246 5.231 0.000
L1.Tirol 0.483630 0.035161 13.755 0.000
L1.Vorarlberg 0.052372 0.030219 1.733 0.083
L1.Wien -0.050133 0.054882 -0.913 0.361
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.152833 0.051105 2.991 0.003
L1.Burgenland -0.000733 0.035088 -0.021 0.983
L1.Kärnten 0.067129 0.018840 3.563 0.000
L1.Niederösterreich 0.201660 0.073578 2.741 0.006
L1.Oberösterreich -0.069166 0.069565 -0.994 0.320
L1.Salzburg 0.220879 0.037264 5.927 0.000
L1.Steiermark 0.108430 0.048911 2.217 0.027
L1.Tirol 0.083864 0.039766 2.109 0.035
L1.Vorarlberg 0.127895 0.034177 3.742 0.000
L1.Wien 0.108435 0.062071 1.747 0.081
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.358242 0.030247 11.844 0.000
L1.Burgenland 0.007698 0.020767 0.371 0.711
L1.Kärnten -0.025331 0.011151 -2.272 0.023
L1.Niederösterreich 0.230034 0.043549 5.282 0.000
L1.Oberösterreich 0.151183 0.041173 3.672 0.000
L1.Salzburg 0.052412 0.022055 2.376 0.017
L1.Steiermark -0.017334 0.028949 -0.599 0.549
L1.Tirol 0.122103 0.023537 5.188 0.000
L1.Vorarlberg 0.072774 0.020228 3.598 0.000
L1.Wien 0.049709 0.036738 1.353 0.176
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039109 0.164748 0.183975 0.171500 0.147180 0.130843 0.068244 0.221152
Kärnten 0.039109 1.000000 0.002673 0.132630 0.027509 0.099126 0.430712 -0.048610 0.101848
Niederösterreich 0.164748 0.002673 1.000000 0.350283 0.174241 0.318557 0.135218 0.194317 0.342531
Oberösterreich 0.183975 0.132630 0.350283 1.000000 0.237310 0.344757 0.184049 0.180843 0.274928
Salzburg 0.171500 0.027509 0.174241 0.237310 1.000000 0.157481 0.141275 0.154492 0.142446
Steiermark 0.147180 0.099126 0.318557 0.344757 0.157481 1.000000 0.166069 0.149409 0.099021
Tirol 0.130843 0.430712 0.135218 0.184049 0.141275 0.166069 1.000000 0.125431 0.165581
Vorarlberg 0.068244 -0.048610 0.194317 0.180843 0.154492 0.149409 0.125431 1.000000 0.022081
Wien 0.221152 0.101848 0.342531 0.274928 0.142446 0.099021 0.165581 0.022081 1.000000